package im.yisme.server.servlet;

import im.yisme.server.database.PlatformData;
import im.yisme.server.vo.ServerLyricsVO;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;

public class UploadServlet extends HttpServlet{

	/**
	 * 
	 */
	private static final long serialVersionUID = 7706421097771100980L;
	
	public void doGet(HttpServletRequest request, HttpServletResponse response){
		doPost(request, response);
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response){
		CharacterEncoding.setCharacterEncoding(request, response);
		
		String artist = request.getParameter("artist");
		String name = request.getParameter("name");
		ServerLyricsVO lyricsVO = new ServerLyricsVO(0, artist, name, 0);
		
		long remoteId = new PlatformData().addLyrics(lyricsVO);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("remoteId", remoteId);
		try {
			response.getWriter().print(jsonObject.toJSONString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
